import { http } from "@/utils/http";
import type { ResultProps } from "@/api/user";

export const getChart = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/formula/charts", {
    data
  });
};

export const getTopCharts = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/formula/topCharts", {
    data
  });
};

export const getChartsList = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/formula/chartsList", {
    data
  });
};

export const deviceCountCharts = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/count/deviceCountCharts", {
    data
  });
};

export const formulaHomeAmount = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/formula/homeAmount", {
    data
  });
};

export interface TeaFormulaStatsProps {
  formula_subid: string;
  formula_name: string;
  total_tea_count: number;
  total_num: number;
  attrs: AttrProps[];
}

export interface AttrProps {
  num: number;
  count: number;
  attr: string;
  tea_count: number;
}

export const teaFormulaStats = (data?: object) => {
  return http.requestJson<ResultProps<TeaFormulaStatsProps[]>>(
    "post",
    "/count/tea/formulaStats",
    {
      data
    }
  );
};

export const getGeoCode = (params?: object) => {
  return http.request<ResultProps<any>>(
    "post",
    "https://lbs.amap.com/service/api/restapi",
    {
      params
    }
  );
};
